package chapter05

/**
 * 练习
 */
object Test08_Practice {
  def main(args: Array[String]): Unit = {
    //练习1  输入 0, "", '0' 为false、其他都是true
    val fun = (i: Int, s: String, c: Char) => {
      if (i == 0 && s == "" && c == 0) false else true
    }

    println(fun(0, "", '0'))
    println(fun(0, "", '1'))
    println(fun(23, "", '0'))
    println(fun(0, "hello", '0'))


    //2、练习
    def func(i: Int): String => (Char => Boolean) = {
      def f1(s: String): Char => Boolean = {
        def f2(c: Char): Boolean = {
          if (i == 0 && s == "" && c == '0') false else true
        }

        f2
      }

      f1
    }

    println(func(0)("")('0'))
    println(func(0)("1")('0'))
    println(func(1)("1")('0'))
    println(func(1)("1")('2'))


    //匿名函数简写
    //    def func1(i: Int): String => (Char => Boolean) = {
    //      def f2(c: Char): Boolean = {
    //        if (i == 0 && s == "" && c == "0") false else true
    //      }
    //      f2
    //    }

    def func1(i: Int): String => (Char => Boolean) = {
      s => {
        c =>  if (i == 0 && s == "" && c == '0') false else true
      }
    }

    println("############################")
    println(func1(0)("")('0'))
    println(func1(0)("1")('0'))
    println(func1(1)("1")('0'))
    println(func1(1)("1")('2'))

  }
}
